package com.pearadmin.pro.modules.sys.service.impl;


import com.pearadmin.pro.common.web.base.BaseController;
import com.pearadmin.pro.common.web.domain.Result;
import com.pearadmin.pro.modules.sys.domain.SysRetrievePwdEntity;
import com.pearadmin.pro.modules.sys.repository.SysUserRepository;
import com.pearadmin.pro.modules.sys.service.SysRetrievePwdService;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class SysRetrievePwdServiceImpl extends BaseController implements SysRetrievePwdService {


    @Resource // 用户持久层
    private SysUserRepository sysUserRepository;
    @Resource // 密码编码器
    private PasswordEncoder passwordEncoder;

    @Override
    public Result resetPassword(SysRetrievePwdEntity sysRetrievePwd) {
        int i = sysUserRepository.updatePwdByUserName(sysRetrievePwd.getUserName(), passwordEncoder.encode(sysRetrievePwd.getNewPassword()));
        if (i > 0) {
            return success();
        }
        return failure("重置失败");
    }
}
